/**
 * @class common.colorPicker
 * @extends common.base.object
 * 颜色选择器
 */
define(function (require) {
    var Base = require('./base/object'),
        Tpl = require('text!./templates/colorPicker.html');
    require('colpick');
    return Base.extend({
        initialize: function (params) {
            Base.prototype.initialize.apply(this, [params]);
            this.render(Tpl, params, params.wrap);

            var $btn = $('.btn', params.wrap),
                _this = this;

            $btn.colpick({
                colorScheme: 'dark',
                layout: 'rgb',
                color: params.background.substring(1),
                flat: true,
                onSubmit: function (hsb, hex, rgb, el) {
                    $btn.css('background-color', '#' + hex);
                    $(el).colpickHide();
                    params.success.apply(_this, [hex]);
                }
            });
            $('.colpick', params.wrap).hide();
            $btn.click(function (event) {
                if ($('.colpick', this)[0].contains(event.target)) {
                    return false;
                }
                if ($('.colpick:visible', this).size()) {
                } else {
                    $('.colpick', this).show();
                }
            });
        }
    });
});